#include "cvm_cpp.h"
#include "cvm_assembler.h"
#include "cvm_cpp_tests.h"

namespace cvm
{
	Define::~Define() { delete stream; }
	size_t Define::Count() { return stream->vec.size(); }
	Token* Define::At(size_t i) { return stream->vec[i]; }

	TokenStream* operator>(TokenStream* a, const Token& b) { return a->Add(b.Clone()); }
	TokenStream* operator>(TokenStream* a, Define& b) { return a->Add(new Function(&b)); }
	TokenStream* Begin() { return new TokenStream(); }
	Push<int> int_(int x) { return Push<int>(x); }
	OpArg* arg_(int x) { return new OpArg(x); }

	std::ostream& operator<<(std::ostream& os, Val* x) 
	{
		switch (x->type)
		{
		case ByteType:		return os << x->data.ByteData.val;
		case IntType:		return os << x->data.IntData.val;
		case FloatType:		return os << x->data.FloatData.val;
		case DoubleType:	return os << x->data.DoubleData.val;
		case ObjectType: 
			return os 
				<< "Object(code=" 
				<< std::hex 
				<< (void*)obj_code(x) 
				<< ", data=" 
				<< obj_array(x)
				<< ")" 
				<< std::dec;
		default: 
			throw std::exception("Unhandled type");
		}
	}
}

int main() 
{
	cvm::RunTests();
	return 0;
}
